#include "../StdAfx.h"
#include ".\logfile.h"

const char cLogFile[] = "logfile.log";

CLogFile::CLogFile(void)
{
	m_pFile = fopen(cLogFile, "a");
	m_bDebugPrint = 0;
}

CLogFile::~CLogFile(void)
{
	if(m_pFile)
		fclose(m_pFile);
	m_pFile = NULL;
}

void CLogFile::Dbg(LPCTSTR format, ...)
{
	if(!m_bDebugPrint) return;
	if(!m_pFile) return;
	CString c;
	CTime tm = CTime::GetCurrentTime();
	va_list marker;
	va_start(marker, format);
	c.FormatV(format, marker);
	fprintf(m_pFile, "%02d.%02d.%04d %02d:%02d:%02d  %s\n",
		tm.GetDay(), tm.GetMonth(), tm.GetYear(),
		tm.GetHour(), tm.GetMinute(), tm.GetSecond(), (LPCTSTR)c );
	va_end(marker);
}

void CLogFile::Add(LPCTSTR format, ...)
{
	if(!m_pFile) return;
	CString c;
	CTime tm = CTime::GetCurrentTime();
	va_list marker;
	va_start(marker, format);
	c.FormatV(format, marker);
	fprintf(m_pFile, "%02d.%02d.%04d %02d:%02d:%02d  %s\n",
		tm.GetDay(), tm.GetMonth(), tm.GetYear(),
		tm.GetHour(), tm.GetMinute(), tm.GetSecond(), (LPCTSTR)c );
	va_end(marker);
}
